#include "SSVEP_Dialog.h"
#include <wx/msw/registry.h>

BEGIN_EVENT_TABLE( SSVEP_Dialog, wxDialog )
EVT_BUTTON(wxID_OK,SSVEP_Dialog::OnOk)
END_EVENT_TABLE()

SSVEP_Dialog::SSVEP_Dialog(void):SSVEP_Conf(NULL,-1)
{
	LoadRegistry();
}

SSVEP_Dialog::~SSVEP_Dialog(void)
{
	

}
void SSVEP_Dialog::LoadRegistry(void)
{
	long int Temp;
	wxRegKey *pRegKey = new wxRegKey(_("HKEY_LOCAL_MACHINE\\Software\\SENSIBILAB\\SSVEP"));

	if( !pRegKey->Exists() )
	{
		pRegKey->Create();
		//will create a new value MYVALUE and set it to 12
		pRegKey->SetValue(_("Left"),0);
		pRegKey->SetValue(_("Right"),0);
		pRegKey->SetValue(_("Up"),0);
		pRegKey->SetValue(_("Down"),0);
		//Query for the Value and Retrieve it
	}

	pRegKey->QueryValue(_("Left"),&Temp);
	m_Left->Select(Temp);
	pRegKey->QueryValue(_("Right"),&Temp);
	m_Right->Select(Temp);
	pRegKey->QueryValue(_("Up"),&Temp);
	m_Up->Select(Temp);
	pRegKey->QueryValue(_("Down"),&Temp);
	m_Down->Select(Temp);
//	pRegKey->QueryValue(_("EDA_COM"),&Eda);
//	panel->EdaCom->Select(Eda);

	delete pRegKey;

}

void SSVEP_Dialog::SaveRegistry(void)
{
	long int Temp;
	wxRegKey *pRegKey = new wxRegKey(_("HKEY_LOCAL_MACHINE\\Software\\SENSIBILAB\\SSVEP"));

	if( !pRegKey->Exists() )
	{
		pRegKey->Create();
	}

	Temp = m_Left->GetSelection();
	pRegKey->SetValue(_("Left"),Temp);

	Temp = m_Right->GetSelection();
	pRegKey->SetValue(_("Right"),Temp);

	Temp = m_Up->GetSelection();
	pRegKey->SetValue(_("Up"),Temp);

	Temp = m_Down->GetSelection();
	pRegKey->SetValue(_("Down"),Temp);

	delete pRegKey;
}

void SSVEP_Dialog::OnOk(wxCommandEvent& event)
{

	short int Values[]={43, 37, 32, 28, 26, 23, 21, 20, 18, 17, 16, 15};

	SelPeriods[2] = Values[m_Up->GetSelection()];
	SelPeriods[3] = Values[m_Down->GetSelection()];
	SelPeriods[1] = Values[m_Right->GetSelection()];
	SelPeriods[0] = Values[m_Left->GetSelection()];

	Sigs[0] = m_SigO1->IsChecked();
	Sigs[1] = m_SigOz->IsChecked();
	Sigs[2] = m_SigO2->IsChecked();
	Sigs[3] = m_SigP3->IsChecked();
	Sigs[4] = m_SigPz->IsChecked();
	Sigs[5] = m_SigP4->IsChecked();
	Sigs[6] = m_SigT5->IsChecked();
	Sigs[7] = m_SigT6->IsChecked();

	
	Refs[0] = m_RefO1->IsChecked();
	Refs[1] = m_RefOz->IsChecked();
	Refs[2] = m_RefO2->IsChecked();
	Refs[3] = m_RefP3->IsChecked();
	Refs[4] = m_RefPz->IsChecked();
	Refs[5] = m_RefP4->IsChecked();
	Refs[6] = m_RefT5->IsChecked();
	Refs[7] = m_RefT6->IsChecked();

	SaveRegistry();
	Close();

	/*m_Up;
	m_Down;
	m_Left;
	M_Right;*/
}


